package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl  implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;


    @Override
    public PageResult<Activity> selectActivityList(ActivityDto activityDto) {
        //1.设置分页参数
        PageHelper.startPage(activityDto.getPage(), activityDto.getPageSize());
        ///2.调用mapper查询数据
        List<Activity> activityList = activityMapper.selectActivityList(activityDto);
        Page<Activity> page = (Page<Activity>) activityList;
        return new PageResult<>(page.getTotal(),page.getResult());
    }
    //删除活动
    @Override
    public void deleteActivityById(Integer id) {
        activityMapper.deleteById(id);
    }
    //添加活动
    @Override
    public void addActivity(Activity activity) {
        //1.一定记得补全参数
        activity.setUpdateTime(LocalDateTime.now());
        activity.setCreateTime(LocalDateTime.now());
            activityMapper.insertActivity(activity);

    }

    @Override
    public Activity selectActivityById(Integer id) {
        Activity ac = activityMapper.selectActivityById(id);
        return ac;
    }

    @Override
    public void updateActivity(Activity activity) {
        activityMapper.updateActivity(activity);
    }

    @Override
    public List<Activity> selectActivityByType(Integer type) {
         List<Activity> activityList = activityMapper.selectActivityByType(type);
        return activityList;
    }


}
